package appconfig

import (
	"github.com/spf13/viper"
	"github.com/zeromicro/go-zero/core/logx"
)

type AppConfig struct {
	Mysql
	Redis
}

type Mysql struct {
	Host     string
	Port     int
	User     string
	Password string
	Database string
}

type Redis struct {
	Host     string
	Port     int
	Password string
}

var AppConf AppConfig

func Init() {
	var err error

	viper.SetConfigFile("./appconfig/dev.yaml")

	err = viper.ReadInConfig()
	if err != nil {
		panic("读取配置文件失败:" + err.Error())
	}

	if err = viper.Unmarshal(&AppConf); err != nil {
		panic("解析配置文件失败:" + err.Error())
	}

	logx.Info("动态配置读取成功:", AppConf)

}
